package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.MerchantApplication;
import service.MerchantApplicationManager;
import service.factory.ManagerFactory;
import sun.misc.BASE64Decoder;

public class GetMerchantIDCardServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private MerchantApplicationManager manager = null;

    public GetMerchantIDCardServlet() {
        super();
        manager = ManagerFactory.getApplicationManagerInstance();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		MerchantApplication merchant = manager.getByName(name);
		String[] split = merchant.getIdCard().split(",");
        byte[] imageByte;
        BASE64Decoder decoder = new BASE64Decoder();
        imageByte = decoder.decodeBuffer(split[1]);
		response.getOutputStream().write(imageByte);
	}
}
